package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RecommendSongs;
import com.ruoyi.system.service.IRecommendSongsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * recommendController
 * 
 * @author wayi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/songs")
public class RecommendSongsController extends BaseController
{
    @Autowired
    private IRecommendSongsService recommendSongsService;

    /**
     * 查询recommend列表
     */
    @PreAuthorize("@ss.hasPermi('system:songs:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecommendSongs recommendSongs)
    {
        startPage();
        List<RecommendSongs> list = recommendSongsService.selectRecommendSongsList(recommendSongs);
        return getDataTable(list);
    }

    /**
     * 导出recommend列表
     */
    @PreAuthorize("@ss.hasPermi('system:songs:export')")
    @Log(title = "recommend", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecommendSongs recommendSongs)
    {
        List<RecommendSongs> list = recommendSongsService.selectRecommendSongsList(recommendSongs);
        ExcelUtil<RecommendSongs> util = new ExcelUtil<RecommendSongs>(RecommendSongs.class);
        util.exportExcel(response, list, "recommend数据");
    }

    /**
     * 获取recommend详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:songs:query')")
    @GetMapping(value = "/{trackId}")
    public AjaxResult getInfo(@PathVariable("trackId") Long trackId)
    {
        return success(recommendSongsService.selectRecommendSongsByTrackId(trackId));
    }

    /**
     * 新增recommend
     */
    @PreAuthorize("@ss.hasPermi('system:songs:add')")
    @Log(title = "recommend", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecommendSongs recommendSongs)
    {
        return toAjax(recommendSongsService.insertRecommendSongs(recommendSongs));
    }

    /**
     * 修改recommend
     */
    @PreAuthorize("@ss.hasPermi('system:songs:edit')")
    @Log(title = "recommend", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecommendSongs recommendSongs)
    {
        return toAjax(recommendSongsService.updateRecommendSongs(recommendSongs));
    }

    /**
     * 删除recommend
     */
    @PreAuthorize("@ss.hasPermi('system:songs:remove')")
    @Log(title = "recommend", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trackIds}")
    public AjaxResult remove(@PathVariable Long[] trackIds)
    {
        return toAjax(recommendSongsService.deleteRecommendSongsByTrackIds(trackIds));
    }
}
